package com.aop.service;

import com.aop.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public List<String> getNames() {
        System.out.println("UserServiceImpl...getNames");
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if(1==2) {
            throw new RuntimeException("发生错误了");
        }
        return userDao.getNames();
    }

    @Override
    public void hello() {
        if(Math.random()*10>5){
            throw new RuntimeException("天气不好，无法访问");
        }
        System.out.println("UserServiceImpl...hello");
    }

    @Override
    public int add(int num) {
        System.out.println("UserServiceImpl...add");
        System.out.println("接收到参数:" + num);
        return num + 1;
    }
}
